//
//  NYDaoLanChoiceView.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2020/12/30.
//  Copyright © 2020 叁拾叁. All rights reserved.
//

import UIKit

class DYDaoLanChoiceView: UIView {
    
    var items:[RYTitleImgView] = [RYTitleImgView]()
    public var clickChoiceClosure: ((Int) -> Void)?
    
    public var lineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0xE6E6E6)
        return v
    }()

    init(frame: CGRect, titles: [String]) {
        super.init(frame: frame)
        
        initViews(titles: titles)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    public func configureView() {
        
    }
    
    fileprivate func initViews(titles: [String]) {
        
        for (i, value) in titles.enumerated() {
            
            let v: RYTitleImgView = RYTitleImgView(frame: CGRect.zero, type: .imgRight, imgSuperViewMargin: 0, imgTitleMargin: 2)
            v.imageV.image = UIImage(named: "choice_arrow")
            v.normalName = "choice_arrow"
            v.selectName = "choice_arrow_up"
            v.textLb.text = value
            v.textLb.font = UIFont.systemFont(ofSize: 15)
            v.textLb.textColor = UIColor(hex: 0x5C5C5C)
            v.tapClosure = {[weak self] (index, _) in
                if let weakSelf = self {
                    weakSelf.clickChoiceClosure?(i)
                }
            }
            v.bgView.backgroundColor = UIColor.white
            v.backgroundColor = UIColor.white
            addSubview(v)
            let itemWidth:CGFloat = 51.0
            let guding = 15.0*2.0 + itemWidth * CGFloat(titles.count)
            let margin = (SCREEN_WIDTH - guding)/CGFloat(titles.count - 1)
            v.snp.makeConstraints { (make) in
                make.centerY.equalToSuperview()
                make.left.equalToSuperview().offset(15.0 + (margin+itemWidth)*CGFloat(i))
                make.height.equalTo(15.0.autoWidth())
            }
            items.append(v)
        }
        
        addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(0.5.autoWidth())
        }
    }

}
